package com.tengju.bff.interfaces.manage.crm.user;

import com.tengju.bff.interfaces.manage.crm.user.facade.CrmMarketFacade;
import com.tengju.bff.interfaces.manage.crm.user.vo.CrmMarketAnalysisMarketRateQueryForm;
import com.tengju.bff.interfaces.manage.crm.user.vo.MonthMarketAnalysisVO;
import com.tengju.bff.interfaces.manage.crm.user.vo.PageMarketRateVO;
import com.tengju.bff.interfaces.shared.ApiResponse;
import com.tengju.bff.interfaces.shared.servlet.ManageEntrance;
import com.tengju.data.domain.model.user.UserIdCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * @Author: 李大仙
 * @Date: 2021/4/1 9:03 下午
 */
@Slf4j
@Validated
@RestController
@Api(tags = "总监CRM-腾炬市场指数分析接口")
@ManageEntrance
@RequestMapping(value = "manage/crm/market")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class CrmMarketController {

    private final CrmMarketFacade crmMarketFacade;

    @ApiOperation(value = "市场指数分析接口-品类分析", notes = "市场指数分析接口")
    @RequestMapping(value = "typeAnalysis", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponse<MonthMarketAnalysisVO> typeAnalysis(@NotNull(message = "月份不能为空") Integer month,
                                                           @NotNull(message = "用户idCode不能为空") Long idCode) {
        MonthMarketAnalysisVO vo = crmMarketFacade.typeAnalysis(UserIdCode.of(idCode), month);
        return ApiResponse.newSuccess(vo);
    }

    @ApiOperation(value = "市场指数分析接口-市场占比分析", notes = "市场指数分析接口")
    @RequestMapping(value = "rateAnalysis", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponse<PageMarketRateVO> rateAnalysis(@Valid CrmMarketAnalysisMarketRateQueryForm queryForm) {
        PageMarketRateVO vo = crmMarketFacade.rateAnalysis(queryForm);
        return ApiResponse.newSuccess(vo);
    }
}
